


/*
'===============================================================================
'  HNG.Portal.BL.GroupAndMenuManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class GroupAndMenuManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_GroupId="GroupId";
				
				public const String Field_MenuId="MenuId";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public GroupAndMenuManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_GroupId,typeof(int));
			
						
			
			dt.Columns.Add(Field_MenuId,typeof(int));
			
			            
            return dt;			
		}
			
		public GroupAndMenuEntity Convert_Entity(GroupAndMenuEntity _GroupAndMenuEntity,GroupAndMenuEntity _GroupAndMenuEntity_XML)
		{	
			
				
			_GroupAndMenuEntity.GroupId= _GroupAndMenuEntity_XML.GroupId;
				
			_GroupAndMenuEntity.MenuId= _GroupAndMenuEntity_XML.MenuId;
				
			
			return _GroupAndMenuEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public GroupAndMenuEntity Insert(GroupAndMenuEntity GroupAndMenuEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(GroupAndMenuEntity, true);
			}
			return GroupAndMenuEntity;
		}

		
		public GroupAndMenuEntity Insert(int GroupId, int MenuId)
		{
			GroupAndMenuEntity _GroupAndMenuEntity = new GroupAndMenuEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_GroupAndMenuEntity.GroupId = GroupId;
				_GroupAndMenuEntity.MenuId = MenuId;
				adapter.SaveEntity(_GroupAndMenuEntity, true);
			}
			return _GroupAndMenuEntity;
		}

		public GroupAndMenuEntity Insert()
		{
			GroupAndMenuEntity _GroupAndMenuEntity = new GroupAndMenuEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				adapter.SaveEntity(_GroupAndMenuEntity, true);
			}
			return _GroupAndMenuEntity;
		}

		public bool Update(GroupAndMenuEntity _GroupAndMenuEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(GroupAndMenuFields.GroupId == _GroupAndMenuEntity.GroupId);
					_PredicateExpression.Add(GroupAndMenuFields.MenuId == _GroupAndMenuEntity.MenuId);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_GroupAndMenuEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(GroupAndMenuEntity _GroupAndMenuEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_GroupAndMenuEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int GroupId, int MenuId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				GroupAndMenuEntity _GroupAndMenuEntity = new GroupAndMenuEntity(GroupId, MenuId);
				if (adapter.FetchEntity(_GroupAndMenuEntity))
				{
				
					adapter.SaveEntity(_GroupAndMenuEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int GroupId, int MenuId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				GroupAndMenuEntity _GroupAndMenuEntity = new GroupAndMenuEntity(GroupId, MenuId);
				if (adapter.FetchEntity(_GroupAndMenuEntity))
				{
					adapter.DeleteEntity(_GroupAndMenuEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("GroupAndMenuEntity", null);
			}
		}
		
		
		public int DeleteByGroupId(int GroupId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GroupAndMenuFields.GroupId == GroupId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("GroupAndMenuEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByMenuId(int MenuId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GroupAndMenuFields.MenuId == MenuId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("GroupAndMenuEntity", filter);
			}
			return toReturn;
		}
		

		
		public GroupAndMenuEntity SelectOne(int GroupId, int MenuId)
		{
			GroupAndMenuEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				GroupAndMenuEntity _GroupAndMenuEntity = new GroupAndMenuEntity(GroupId, MenuId);
				if (adapter.FetchEntity(_GroupAndMenuEntity))
				{
					toReturn = _GroupAndMenuEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _GroupAndMenuCollection = new EntityCollection( new GroupAndMenuEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GroupAndMenuCollection, null, 0, null);
			}
			return _GroupAndMenuCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GroupAndMenuCollection = new EntityCollection(new GroupAndMenuEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GroupAndMenuCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectByGroupId(int GroupId)
		{
			EntityCollection _GroupAndMenuCollection = new EntityCollection(new GroupAndMenuEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GroupAndMenuFields.GroupId == GroupId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GroupAndMenuCollection, filter, 0, null);
			}
			return _GroupAndMenuCollection;
		}
		
		// Return DataTable
		public DataTable SelectByGroupIdRDT(int GroupId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GroupAndMenuCollection = new EntityCollection(new GroupAndMenuEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GroupAndMenuFields.GroupId == GroupId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GroupAndMenuCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByMenuId(int MenuId)
		{
			EntityCollection _GroupAndMenuCollection = new EntityCollection(new GroupAndMenuEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GroupAndMenuFields.MenuId == MenuId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GroupAndMenuCollection, filter, 0, null);
			}
			return _GroupAndMenuCollection;
		}
		
		// Return DataTable
		public DataTable SelectByMenuIdRDT(int MenuId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GroupAndMenuCollection = new EntityCollection(new GroupAndMenuEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GroupAndMenuFields.MenuId == MenuId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GroupAndMenuCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
